538D - Weird Chess - CodeForces Solution


brute force constructive algorithms implementation *1800

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <algorithm>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdio>
//#include <nits/stdc++.h>
#define debug cout << "***";
#define inf 1000000000000000005
#define threesum cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false);

using namespace std;

int gcd(int a, int b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {
    return ((a * b) / (gcd(a, b)));
}

bool isPrime(int n)
{
    if (n <= 1)
        return false;
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;
    return true;
}

//printf("%.10f\n", (double)sum / n);

char board[55][55], ans[105][105];

int main() {
    threesum
    int n;cin >> n;
    vector<pair<int, int>> mohre, attacked;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> board[i][j];
            if (board[i][j] == 'o') mohre.emplace_back(i, j);
            if (board[i][j] == 'x') attacked.emplace_back(i, j);
        }
    }
    if (n == 1) {
        cout << "YES\no";
    }
    else {
        if (attacked.size() == 0) {
            cout << "YES\n";
            const int len = 2 * n - 1, mid = len / 2;
            for (int i = 0; i < len; ++i) {
                for (int j = 0; j < len; ++j) {
                    if (i == mid && j == mid)cout << 'o';
                    else cout << '.';
                }
                cout << "\n";
            }
        }
        else {
            const int len = 2 * n - 1, mid = len / 2;
            for (int i = 0; i < len; ++i) {
                for (int j = 0; j < len; ++j) {
                    ans[i][j] = 'x';
                }
            }
            ans[mid][mid] = 'o';
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    if (board[i][j] != '.') continue;
                    for (int k = 0; k < mohre.size(); ++k) {
                        pair<int, int> d{ mid + (i - mohre[k].first), mid + (j - mohre[k].second) };
                        if (d.first >= 0 && d.first < len && d.second >= 0 && d.second < len) {
                            ans[d.first][d.second] = '.';
                        }
                    }
                }
            }
            bool ok = false;
            for (int i = 0; i < attacked.size(); ++i) {
                ok = false;
                for (int j = 0; j < mohre.size(); ++j) {
                    if (ans[mid + attacked[i].first - mohre[j].first][mid + attacked[i].second - mohre[j].second] == 'x') ok = true;
                }
                if (!ok) break;
            }
            if (!ok) cout << "NO\n";
            else {
                cout << "YES\n";
                for (int i = 0; i < len; ++i) {
                    for (int j = 0; j < len; ++j) {
                        cout << ans[i][j];
                    }
                    cout << "\n";
                }
            }
        }
    }
}


Comments

Submit
0 Comments
More Questions

1528B - Kavi on Pairing Duty
339B - Xenia and Ringroad
189A - Cut Ribbon
1182A - Filling Shapes
82A - Double Cola
45A - Codecraft III
1242A - Tile Painting
1663E - Are You Safe
1663D - Is it rated - 3
1311A - Add Odd or Subtract Even
977F - Consecutive Subsequence
939A - Love Triangle
755A - PolandBall and Hypothesis
760B - Frodo and pillows
1006A - Adjacent Replacements
1195C - Basketball Exercise
1206A - Choose Two Numbers
1438B - Valerii Against Everyone
822A - I'm bored with life
9A - Die Roll
1430B - Barrels
279B - Books
1374B - Multiply by 2 divide by 6
1093B - Letters Rearranging
1213C - Book Reading
1468C - Berpizza
1546B - AquaMoon and Stolen String
1353C - Board Moves
902A - Visiting a Friend
299B - Ksusha the Squirrel